home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / String.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  4.4 KB  |  116 lines  |  [TEXT/Moml]

  1. (* String -- SML Basis Library *)
  2.  
  3. local 
  4.     type char = Char.char
  5. in
  6.     type string = string
  7.     val maxSize   : int
  8.     val size      : string -> int
  9.     val sub       : string * int -> char
  10.     val substring : string * int * int -> string
  11.     val extract   : string * int * int option -> string
  12.     val concat    : string list -> string
  13.     val ^         : string * string -> string
  14.     val str       : char -> string
  15.     val implode   : char list -> string 
  16.     val explode   : string -> char list
  17.  
  18.     val translate : (char -> string) -> string -> string
  19.     val tokens    : (char -> bool) -> string -> string list
  20.     val fields    : (char -> bool) -> string -> string list
  21.     val isPrefix  : string -> string -> bool
  22.  
  23.     val compare   : string * string -> order
  24.     val collate   : (char * char -> order) -> string * string -> order
  25.  
  26.     val fromString  : string -> string option     (* ML escape sequences *)
  27.     val toString    : string -> string            (* ML escape sequences *)
  28.     val fromCString : string -> string option     (* C escape sequences *)
  29.     val toCString   : string -> string            (* C escape sequences *)
  30.  
  31.     val <  : string * string -> bool
  32.     val <= : string * string -> bool
  33.     val >  : string * string -> bool
  34.     val >= : string * string -> bool
  35. end
  36.  
  37. (* the type [string] is the type of string of characters.
  38.  
  39.    [maxSize] is the maximal number of characters in a string.
  40.  
  41.    [size s] is the number of characters in string s.
  42.  
  43.    [sub(s, i)] is the i'th character of s, counting from zero.  
  44.    Raises Subscript if i<0 or i>=size s.
  45.  
  46.    [substring(s, i, n)] is the string s[i..i+n-1].  Raises Subscript
  47.    if i<0 or n<0 or i+n>size s.  Equivalent to extract(s, i, SOME n).
  48.  
  49.    [extract (s, i, NONE)] is the string s[i..size s-1].
  50.    Raises Subscript if i<0 or i>size s. 
  51.  
  52.    [extract (s, i, SOME n)] is the string s[i..i+n-1].
  53.    Raises Subscript if i<0 or n<0 or i+n>size s. 
  54.  
  55.    [concat ss] is the concatenation of all the strings in ss.
  56.    Raises Size if the sum of their sizes is greater than maxSize.
  57.  
  58.    [s1 ^ s2] is the concatenation of strings s1 and s2.
  59.  
  60.    [str c] is the string of size one which contains the character c.
  61.  
  62.    [implode cs] is the string containing the characters in the list cs.
  63.    Equivalent to concat (List.map str cs).
  64.  
  65.    [explode s] is the list of characters in the string s.
  66.  
  67.    [translate f s] applies f to every character of s, from left to
  68.    right, and returns the concatenation of the results.  Raises Size
  69.    if the sum of their sizes is greater than maxSize.  Equivalent to
  70.    concat (List.map f (explode s)).
  71.  
  72.    [tokens p s] returns the list of tokens in s, from left to right, 
  73.    where a token is a non-empty maximal substring of s not containing 
  74.    any delimiter, and a delimiter is a character satisfying p.
  75.  
  76.    [fields p s] returns the list of fields in s, from left to right, 
  77.    where a field is a (possibly empty) maximal substring of s not 
  78.    containing any delimiter, and a delimiter is a character satisfying p.
  79.  
  80.    Two tokens may be separated by more than one delimiter, whereas two
  81.    fields are separated by exactly one delimiter.  If the only delimiter 
  82.    is the character #"|", then
  83.        "abc||def" contains two tokens:   "abc" and "def"
  84.        "abc||def" contains three fields: "abc" and "" and "def"
  85.  
  86.    [isPrefix s1 s2] is true if s1 is a prefix of s2.  
  87.    That is, if there exists a string t such that s1 ^ t = s2.
  88.  
  89.    [fromString s] scans the string s as an ML source program string,
  90.    converting escape sequences into the appropriate characters.  Does
  91.    not skip leading whitespace.
  92.  
  93.    [toString s] returns a string corresponding to s, with
  94.    non-printable characters replaced by ML escape sequences.
  95.    Equivalent to String.translate Char.toString.
  96.  
  97.    [fromCString s] scans the string s as a C source program string,
  98.    converting escape sequences into the appropriate characters.  Does
  99.    not skip leading whitespace.
  100.  
  101.    [toCString s] returns a string corresponding to s, with
  102.    non-printable characters replaced by C escape sequences.
  103.    Equivalent to String.translate Char.toCString.
  104.  
  105.    [compare (s1, s2)] does lexicographic comparison, using the
  106.    standard ordering Char.compare on the characters.  Returns LESS,
  107.    EQUAL, or GREATER, according as s1 is less than, equal to, or
  108.    greater than s2.
  109.  
  110.    [collate cmp (s1, s2)] performs lexicographic comparison, using the 
  111.    given ordering cmp on characters.  
  112.  
  113.    [<], [<=], [>], and [>=] compare strings lexicographically.
  114. *)
  115.  
  116.